#include <QCoreApplication>
#include "Link.h"
#include "Json.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    //初始化SDK
    Link::init();

    //创建GPIO模块
    LinkObject *gpio=Link::create("GPIO");
    gpio->start();

    //获取DEF按键的GPIO名
    QString gpioName=Json::loadFile("/link/config/hardware.json").toMap()["gpio"].toMap()["name"].toString();

    //注册GPIO输入回调
    if(gpio->invoke("registEvent",gpioName).toBool())
    {
        //这里是为了简化代码，实际使用时正常使用Qt信号槽连接newEvent信号到对象槽函数即可
        QObject::connect(gpio,&LinkObject::newEvent,[=](QString type,QVariant info){
            QString name=info.toString();
            qDebug()<<name<<type;
        });
    }

    //直接获取GPIO输入状态，会导致对应GPIO的回调不生效
    //gpio->invoke("getGPIO",gpioName).toBool();

    //以下代码为GPIO输出，请查阅硬件手册，配置好复用
    //检查无误后再调用，避免损坏板卡
    //QVariantList args;
    //args<<"GPIO20_1"<<false;
    //gpio->invoke("setGPIO",args);

    return a.exec();
}

